<script lang="ts" setup>
import { ref, Ref, computed, watch } from "vue";
import enterpriseCV from '@/class/enterpriseCV';
import { enterpriseCVStoreHook } from "@/store/modules/enterpriseCV";


const dialogFormVisible = computed(() => props.isShow);
const formLabelWidth = '100px'

//件
const emits = defineEmits(["closeEdit", "success"])
//保存
const update = async () => {
    await enterpriseCVStoreHook().update(rowData.value)
        .then(rep => {
            if (rep.code == 200) {
                console.log(rep.msg)
            }
        })
    emits("success")

}
const close = () => {
    emits("closeEdit")
}

//传参
const props = defineProps({
    isShow: Boolean,
    info: enterpriseCV
})

const rowData: Ref<enterpriseCV> = ref<enterpriseCV>({
    id: "",
    name: '',
    representative: '',
    registeredCapital: '',
    telephone: '',
    mail: '',
    website: '',
    address: '',
    establishTime: '',
    fileId: "",
    createTime: "",
    updateTime: "",
})

//监听
watch(() => props.info, (newInfo) => {
    if (newInfo) {
        rowData.value = {
            id: newInfo.id,
            name: newInfo.name,
            representative: newInfo.representative,
            registeredCapital: newInfo.registeredCapital,
            telephone: newInfo.telephone,
            mail: newInfo.mail,
            website: newInfo.website,
            address: newInfo.address,
            establishTime: newInfo.establishTime,
            fileId: newInfo.fileId,
            createTime: newInfo.createTime,
            updateTime: newInfo.updateTime,
        }
    }
})
</script>

<template>
    <el-dialog v-model="dialogFormVisible" title="新增" width="40%" @close="$emit('closeEdit')" draggable center>
        <el-form ref="formRef" :model="rowData" label-width="100px" style="padding-top: 0px; padding-bottom: 0px;"
            :validate-on-rule-change="false" :inline="false" label-position="left">
            <el-form-item label="ID" prop="id" :label-width="formLabelWidth">
                <el-input v-model="rowData.id" disabled />
            </el-form-item>
            <el-form-item label="公司名称" prop="name" :label-width="formLabelWidth">
                <el-input v-model="rowData.name" autocomplete="off" />
            </el-form-item>
            <el-form-item label="法定代表人" prop="representative" :label-width="formLabelWidth">
                <el-input v-model="rowData.representative" autocomplete="off" />
            </el-form-item>
            <el-form-item label="注册资本" prop="registeredCapital" :label-width="formLabelWidth">
                <el-input v-model="rowData.registeredCapital" autocomplete="off" />
            </el-form-item>
            <el-form-item label="公司电话" prop="telephone" :label-width="formLabelWidth">
                <el-input v-model="rowData.telephone" autocomplete="off" />
            </el-form-item>
            <el-form-item label="邮箱" prop="mail" :label-width="formLabelWidth">
                <el-input v-model="rowData.mail" type="mail" autocomplete="off" />
            </el-form-item>
            <el-form-item label="官网" prop="website" :label-width="formLabelWidth">
                <el-input v-model="rowData.website" autocomplete="off" />
            </el-form-item>
            <el-form-item label="地址" prop="address" :label-width="formLabelWidth">
                <el-input v-model="rowData.address" autocomplete="off" />
            </el-form-item>
            <el-form-item label="成立时间" prop="establishTime" :label-width="formLabelWidth">
                <el-date-picker v-model="rowData.establishTime" type="date" placeholder="Pick a day" />
            </el-form-item>
            <el-form-item label="简历ID" prop="fileId" :label-width="formLabelWidth">
                <el-input v-model="rowData.fileId" type="text" disabled />
            </el-form-item>
            <el-form-item label="创建时间" prop="createTime" :label-width="formLabelWidth">
                <el-input v-model="rowData.createTime" type="data" disabled />
            </el-form-item>
            <el-form-item label="更新时间" prop="updateTime" :label-width="formLabelWidth">
                <el-input v-model="rowData.updateTime" type="data" disabled />
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="close">关闭</el-button>
                <el-button type="primary" @click="update">
                    修改
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>
